home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 2000
/
MacHack 2000.toast
/
pc
/
The Hacks
/
Softshoe
/
Lisa's Mac Parts
/
Macintosh Memory
/
MasterPointer.h
< prev
next >
Wrap
Text File
|
2000-06-23
|
3KB
|
85 lines
// MasterPointer.h
#ifndef MasterPointer_h
#define MasterPointer_h
#ifndef Integers_h
#include "Integers.h"
#endif
#ifndef Assert_h
#include "Assert.h"
#endif
#ifndef Data_h
#include "Data.h"
#endif
#include <Memory.h>
class MasterPointer
{
private:
void *pointer;
// These don't exist
MasterPointer( const MasterPointer& );
void operator=( const MasterPointer& );
static void ThrowAllocationError( OSErr, void * );
protected:
MasterPointer() {}
public:
enum SystemHeap { systemHeap };
enum Temporary { temporary };
static MasterPointer& MakeEmpty() { return *new MasterPointer; }
static MasterPointer& Make( uint32 size ) { return *new( size ) MasterPointer; }
static MasterPointer& MakeEmptyInSystemHeap() { return *new( systemHeap ) MasterPointer; }
static MasterPointer& MakeInSystemHeap( uint32 size ) { return *new( size, systemHeap ) MasterPointer; }
static MasterPointer& MakeTemporary( uint32 size ) { return *new( size, temporary ) MasterPointer; }
void *operator new( size_t pointerSize );
void *operator new( size_t pointerSize, uint32 blockSize );
void *operator new( size_t pointerSize, SystemHeap );
void *operator new( size_t pointerSize, uint32 blockSize, SystemHeap );
void *operator new( size_t pointerSize, uint32 blockSize, Temporary );
void operator delete( void * );
void *Pointer() const { return pointer; }
::Ptr Ptr() const { return static_cast< ::Ptr>( pointer ); }
::Handle Handle() const { return reinterpret_cast< ::Handle>( const_cast<void **>(&pointer) ); }
bool IsEmpty() const { return pointer == 0; }
void BeEmpty() { EmptyHandle( Handle() ); }
void Allocate( uint32 size ) { Assert( IsEmpty() ); ReallocateHandle( Handle(), int32(size) ); }
uint32 Size() const { Assert( !IsEmpty() ); return uint32( GetHandleSize( Handle() ) ); }
void SetSize( uint32 newSize ) { Assert( !IsEmpty() ); SetHandleSize( Handle(), int32(newSize) ); }
::Data Data() const { return ::Data( Pointer(), Size() ); }
::Data operator*() const { return ::Data( Pointer(), Size() ); }
SignedByte State() const { return HGetState( Handle() ); }
void SetState( SignedByte state ) { HSetState( Handle(), state ); }
void Lock() { HLock( Handle() ); }
void Unlock() { HUnlock( Handle() ); }
void AllowPurging() { HPurge( Handle() ); }
void ForbidPurging() { HNoPurge( Handle() ); }
void BeResource() { HSetRBit( Handle() ); }
void BeNotResource() { HClrRBit( Handle() ); }
static MasterPointer& At( ::Handle h ) { return *reinterpret_cast<MasterPointer *>( h ); }
static MasterPointer& MasterPointerFor( void *p ) { return At( RecoverHandle( static_cast< ::Ptr>(p) ) ); }
void MoveHigh() { MoveHHi( Handle() ); }
void LockHigh() { HLockHi( Handle() ); }
THz Zone() const { return HandleZone( Handle() ); }
};
#endif